# -*- coding: utf-8 -*-

from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

from Quote import Quote
from sqlalchemy import Column, DateTime, String, BigInteger, Float, Integer

class QuoteAdapter(Base):
    __tablename__ = 'market'
    
    id          = Column(BigInteger, primary_key=True)
    contractid  = Column(Integer)
    position    = Column(Integer)
    operation   = Column(Integer)
    side        = Column(Integer)
    price       = Column(Float)
    size        = Column(Float)
    insertdate  = Column(DateTime)
    inserttime  = Column(DateTime)
    
    def __init__(self, quote):
        self.contractid  = quote.contract
        self.position    = quote.position
        #self.operation   = quote.operation
        self.operation   = 0
        self.side        = quote.side
        self.price       = quote.price
        self.size        = quote.size

    def Quote(self):
        return Quote(self.size, 
                     self.price, 
                     self.side, 
                     self.contractid, 
                     self.position, 
                     None)
        